package com.chagee.store.operation.server.controller.pc;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.chagee.base.utils.*;
import com.chagee.store.operation.api.request.SearchSupplierRequest;
import com.chagee.store.operation.api.response.SearchSupplierResponse;
import com.chagee.store.operation.server.facade.StoreTaskRelationFacade;
import com.chagee.store.operation.server.model.param.StoreTaskRelationDetailParam;
import com.chagee.store.operation.server.model.param.StoreTaskRelationRequest;
import com.chagee.store.operation.server.model.param.UpdateDateRequest;
import com.chagee.store.operation.server.model.response.StoreTaskRelation2SetVO;
import com.chagee.store.operation.server.model.response.StoreTaskRelationDetailResponse;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springblade.core.secure.utils.AuthUtil;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.List;

/**
 * 门店-打烊任务配置
 */
@Slf4j
@RestController
@RequestMapping("/taskRelation")
public class StoreTaskRelationController {

	@Resource
	private StoreTaskRelationFacade storeTaskRelationFacade;


	/**
	 * 查询门店已配置任务
	 * @param request
	 * @return
	 */
	@PostMapping("/queryDetail")
	@ApiOperation("查询门店任务信息")
	public HttpResponse<StoreTaskRelationDetailResponse> queryDetail(@RequestBody StoreTaskRelationRequest request) {
		return HttpResponseUtil.success(storeTaskRelationFacade.queryDetail(request));
	}

	/**
	 * 删除-门店打烊任务
	 */
	@PostMapping("/deleteStoreTask")
	@ApiOperation("删除-门店打烊任务")
	public HttpResponse<Boolean> deleteStoreTask(@RequestBody List<Long> request) {
		return HttpResponseUtil.success(storeTaskRelationFacade.deleteStoreTask(request));
	}

	/**
	 * 门店打烊任务
	 */
	@GetMapping("/addStoreTaskQueryBasicTask")
	@ApiOperation("添加门店打烊任务->查询A-B的set B的set  done")
	public HttpResponse<StoreTaskRelation2SetVO> addStoreTaskQueryBasicTask(@RequestParam("storeNo") String storeNo) {
		log.info("StoreTaskRelationController_addStoreTaskQueryBasicTask_request:{}, auth:{}", JSON.toJSONString(storeNo), JSON.toJSONString(AuthUtil.getUser()));
		return HttpResponseUtil.success(storeTaskRelationFacade.addStoreTaskQueryBasicTask(storeNo));
	}

	/**
	 * 添加门店打烊任务  增/删
	 */
	@PostMapping("/addStoreTask")
	@ApiOperation("添加门店打烊任务  增/删")
	public HttpResponse<Boolean> addStoreTask(@RequestBody StoreTaskRelationDetailParam request) {
		log.info("StoreTaskRelationController_addStoreTask_request:{}, auth:{}", JSON.toJSONString(request), JSON.toJSONString(AuthUtil.getUser()));
		return HttpResponseUtil.success(storeTaskRelationFacade.addStoreTaskSave(request));
	}

	@PostMapping("/updateStoreDetailData")
	@ApiOperation("保存开早打烊配置的信息")
	public HttpResponse<Boolean> updateStoreDetailData(@RequestBody @Valid UpdateDateRequest request) {
		log.info("#StoreTaskRelationController.updateStoreDetailData#request{}", JSONObject.toJSONString(request));
		return HttpResponseUtil.success(storeTaskRelationFacade.updateStoreDetailData(request));
	}

	@PostMapping("/supplierList")
	@ApiOperation("供应商列表")
	public HttpResponse<PaginationData<SearchSupplierResponse>> searchSupplier(@RequestBody PaginationRequest<SearchSupplierRequest> request) {
		log.info("#StoreTaskRelationController.searchSupplier#request{}", JSONObject.toJSONString(request));
		return HttpResponseUtil.success(storeTaskRelationFacade.searchSupplier(request));
	}
}
